import { Base } from '../../utils/base.js';

class YcTicket extends Base {
  constructor() {
    super();
  }

  getTebie(aid, callBack) {
    var param = {
      url: 'getTebie?id=' + aid,
      sCallBack: function (data) {
        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  getBuKuanSJrow(id, performId, callBack) {
    var param = {
      url: 'getBuKuanSJrow?aid=' + id + '&performId=' + performId,
      sCallBack: function (data) {
        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  getBuKuanPJrow(id, quyuID, callBack) {
    var param = {
      url: 'getBuKuanPJrow?aid=' + id + '&quyuID=' + quyuID,
      sCallBack: function (data) {
        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  getXinXi(id, callBack) {
    console.log(id);
    var param = {
      url: 'getXinXi/' + id,
      sCallBack: function (data) {
        //console.log(data);
        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  getChaXun(callBack) {
    //console.log(userid);
    var param = {
      url: 'getChaXun',
      sCallBack: function (data) {
        //console.log(data);
        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  getXxCc(id, callBack) {
    var param = {
      url: 'getXxCc/' + id,
      sCallBack: function (data) {
        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  doOrder(products, callBack) {
    //console.log(products);
    var param = {
      url: 'DbkOrder',
      type: 'post',
      data: products,
      sCallBack: function (data) {
        console.log(data); //that.execSetStorageSync(true);

        callBack && callBack(data);
      }
    };
    this.request(param);
  }

  execPay(orderID, callBack) {
    var param = {
      url: 'Dbkpay/pre_order',
      //url: 'pay/pre_order',
      type: 'post',
      data: {
        id: orderID
      },
      sCallBack: function (res) {
        var timeStamp = res.timeStamp;

        if (timeStamp) {
          //可以支付
          tt.requestPayment({
            'timeStamp': timeStamp.toString(),
            'nonceStr': res.nonceStr,
            'package': res.package,
            'signType': res.signType,
            'paySign': res.paySign,
            success: function (res) {
              //console.log(res)
              callBack && callBack(1);
            },
            fail: function () {
              callBack && callBack(0);
            }
          });
        } else {
          callBack && callBack(0);
        }
      }
    };
    this.request(param);
  }

}

export { YcTicket };